package net.alteiar.ui.editor;

import java.awt.Point;
import java.awt.event.MouseEvent;

import net.alteiar.ui.ZoomablePanel;
import net.alteiar.ui.condition.MouseCondition;
import net.alteiar.ui.editor.tools.ImageInfoTool;
import net.alteiar.ui.listener.ConditionMouseAdapter;

public class ImageEditorMouseListener extends ConditionMouseAdapter {

	private ImageInfoTool currentTool;
	private final ZoomablePanel<?> panelImage;

	public ImageEditorMouseListener(MouseCondition condition,
			ZoomablePanel<?> panel) {
		super(condition);

		this.panelImage = panel;
	}

	public void setTool(ImageInfoTool tool) {
		this.currentTool = tool;
	}

	@Override
	protected void realMouseClicked(MouseEvent e) {
		if (currentTool != null) {
			Point imgPos = panelImage.panelToImage(e.getPoint());
			currentTool.doAction(imgPos);
		}
	}

	@Override
	protected void realMousePressed(MouseEvent e) {
		if (currentTool != null) {
			Point imgPos = panelImage.panelToImage(e.getPoint());
			currentTool.doAction(imgPos);
		}
	}

	@Override
	protected void realMouseDragged(MouseEvent e) {
		if (currentTool != null) {
			Point imgPos = panelImage.panelToImage(e.getPoint());
			currentTool.doAction(imgPos);
			currentTool.doTmp(imgPos);
		}
	}

	@Override
	protected void realMouseMoved(MouseEvent e) {
		if (currentTool != null) {
			Point imgPos = panelImage.panelToImage(e.getPoint());
			currentTool.doTmp(imgPos);
		}
	}
}
